
package com.rt.schedulenew.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rt.schedulebase.dto.DictWardDto;
import com.rt.schedulebase.entity.DictWard;
import com.rt.schedulebase.mapper.DictWardMapper;
import com.rt.schedulenew.api.IDictWardService;
import com.rt.schedulenew.utils.base.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictWardServiceImpl extends ServiceImpl<DictWardMapper, DictWard> implements IDictWardService {
    @Override
    public boolean insertSelective(DictWard dictWard) {
        return this.retBool(this.baseMapper.insert(dictWard));
    }

    @Override
    public boolean deleteByPrimaryKey(String key) {
        return this.retBool(this.baseMapper.deleteById(key));
    }

    @Override
    public boolean updateByPrimaryKeySelective(DictWard dictWard) {
        return this.retBool(this.baseMapper.updateById(dictWard));
    }

    @Override
    public DictWard selectByPrimaryKey(String key) {
        return this.baseMapper.selectById(key);
    }

    @Override
    public List<DictWard> getList(DictWardDto dto) {
        QueryWrapper<DictWard> qw = new QueryWrapper<>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("HOSPITAL_CODE", dto.getHospitalCode());
        qw.allEq(map, false);
        if (StringUtils.isNotBlank(dto.getWardCode())) {
            qw.in("WARD_CODE", CommonUtil.split2List(dto.getWardCode()));
        }
        qw.orderByAsc("SORT_NO");
        List<DictWard> list = this.baseMapper.selectList(qw);
        return list;
    }

    @Override
    public List<DictWard> getListAll() {
        return this.baseMapper.selectList(null);
    }

    @Override
    public List<DictWard> getWardList(DictWardDto dto) {
        dto.setClinicAttrList(CommonUtil.split2List(dto.getClinicAttr()));
        List<DictWard> list = this.baseMapper.getWardList(dto);
        return list;
    }
}
